//
//  OnlineOrganizationalLifeTableViewCell.m
//  ShangHaiHuDongApp
//
//  Created by apple on 17/9/2.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "OnlineOrganizationalLifeTableViewCell.h"

@implementation OnlineOrganizationalLifeTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initMyCell];
    }
    return self;
}


-(void)initMyCell{
    [self.contentView addSubview:self.titleImageView];
    [self.contentView addSubview:self.ybTitleLabel];
    [self.contentView addSubview:self.timeLabel];
    [self.contentView addSubview:self.joinPeopleNumberLabel];
    [self.contentView addSubview:self.bottomView];
    
    UIImageView * timeLogoImageView = [[UIImageView alloc]initWithFrame:CGRectMake(1, 1, 1, 1)];
    timeLogoImageView.image = [UIImage imageNamed:@"hdxq_time"];
    [self.contentView addSubview:timeLogoImageView];
    
    self.titleImageView.sd_layout.leftSpaceToView(self.contentView , ItemWidth * 24).topSpaceToView(self.contentView , ItemHeight * 23).widthIs(ItemWidth * 277).bottomSpaceToView(self.contentView , ItemHeight * 41);
    
    self.ybTitleLabel.sd_layout.leftSpaceToView(self.titleImageView , ItemWidth * 18).topSpaceToView(self.contentView , ItemHeight * 24).widthIs(1).heightIs(1);
    
    timeLogoImageView.sd_layout.leftSpaceToView(self.titleImageView , ItemWidth * 18).bottomSpaceToView(self.contentView , ItemHeight * 44).widthIs(ItemWidth * 24).heightIs(ItemWidth * 24);
    
    self.joinPeopleNumberLabel.sd_layout.rightSpaceToView(self.contentView , ItemWidth * 23).bottomSpaceToView(self.contentView , ItemHeight * 36).widthIs(ItemWidth * 150).heightIs(ItemHeight * 40);
    
    self.timeLabel.sd_layout.leftSpaceToView(timeLogoImageView , ItemWidth * 15).bottomSpaceToView(self.contentView , ItemHeight * 36).rightSpaceToView(self.joinPeopleNumberLabel , 1).heightIs(ItemHeight * 40);
    
    self.bottomView.sd_layout.leftSpaceToView(self.contentView , 0).bottomSpaceToView(self.contentView , 0).rightSpaceToView(self.contentView , 0).heightIs(ItemHeight * 16);
}


-(void)setModel:(OnlineOrganizationalLifeModel *)model
{
    _model = model;
    self.ybTitleLabel.sd_layout.leftSpaceToView(self.titleImageView , ItemWidth * 18).topSpaceToView(self.contentView , ItemHeight * 24).widthIs(model.titleSize.width).heightIs(model.titleSize.height + 1);
    [self.ybTitleLabel updateLayout];
    self.ybTitleLabel.attributedText = model.titleAttributedString;
    self.timeLabel.text = [NSDateFormatter stringMonthAndHourAndMintueWithDate:model.START_TIME];
    NSString * joinNumberStr = @"0";
    if (model.ENROLL_NUM.length > 0) {
        joinNumberStr = model.ENROLL_NUM;
    }
    self.joinPeopleNumberLabel.text = [NSString stringWithFormat:@"%@人参与",joinNumberStr];
    NSString *imageString;
    if (model.COVER_JSON.count == 0) {
        imageString = @"111";
    }else{
        imageString = [model.COVER_JSON[0] objectForKey:@"file_path"];
    }
    [self.titleImageView sd_setImageWithURL:CREATEURL(imageString) placeholderImage:PlaceholderImage];
}


-(UIImageView *)titleImageView
{
    if (!_titleImageView) {
        _titleImageView = [[UIImageView alloc]initWithFrame:CGRectMake(1, 1, 1, 1)];
        _titleImageView.contentMode = UIViewContentModeCenter;
        _titleImageView.clipsToBounds = YES;
    }
    return _titleImageView;
}


-(UILabel *)ybTitleLabel
{
    if (!_ybTitleLabel) {
        _ybTitleLabel = [ToolClass creatLabelWithFrame:CGRectMake(1, 1, 1, 1) font:16 textColor:[UIColor textBlackColor] text:@""];
        _ybTitleLabel.numberOfLines = 3;
        _ybTitleLabel.font= LYPFONT(16);
    }
    return _ybTitleLabel;
}

-(UILabel *)timeLabel
{
    if (!_timeLabel) {
        _timeLabel = [ToolClass creatLabelWithFrame:CGRectMake(1, 1, 1, 1) font:14 textColor:[UIColor textLightGrayColor] text:@""];
    }
    return _timeLabel;
}


-(UILabel *)joinPeopleNumberLabel
{
    if (!_joinPeopleNumberLabel) {
        _joinPeopleNumberLabel = [ToolClass creatLabelWithFrame:CGRectMake(1, 1, 1, 1) font:14 textColor:[UIColor zj_colorWithHexString:@"f24141"] text:@""];
        _joinPeopleNumberLabel.textAlignment = NSTextAlignmentRight;
    }
    return _joinPeopleNumberLabel;
}

-(UIView *)bottomView
{
    if (!_bottomView) {
        _bottomView = [[UIView alloc]initWithFrame:CGRectMake(1, 1, 1, 1)];
        _bottomView.backgroundColor = [UIColor themeGrayColor];
    }
    return _bottomView;
}

@end
